﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.CharacterInsultedLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class CharacterInsultedLogEntry : LogEntry, IEncyclopediaLog, IChatNotification
  {
    [SaveableField(110)]
    public readonly Hero Insultee;
    [SaveableField(111)]
    public readonly Hero Insulter;
    [SaveableField(112)]
    private readonly CharacterObject _overWhat;
    [SaveableField(113)]
    private readonly ActionNotes _gameActionNote;

    internal static void AutoGeneratedStaticCollectObjectsCharacterInsultedLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Insultee);
      collectedObjects.Add((object) this.Insulter);
      collectedObjects.Add((object) this._overWhat);
    }

    internal static object AutoGeneratedGetMemberValueInsultee(object o)
    {
      return (object) ((CharacterInsultedLogEntry) o).Insultee;
    }

    internal static object AutoGeneratedGetMemberValueInsulter(object o)
    {
      return (object) ((CharacterInsultedLogEntry) o).Insulter;
    }

    internal static object AutoGeneratedGetMemberValue_overWhat(object o)
    {
      return (object) ((CharacterInsultedLogEntry) o)._overWhat;
    }

    internal static object AutoGeneratedGetMemberValue_gameActionNote(object o)
    {
      return (object) ((CharacterInsultedLogEntry) o)._gameActionNote;
    }

    public override CampaignTime KeepInHistoryTime => CampaignTime.Weeks(240f);

    public override ChatNotificationType NotificationType
    {
      get => this.CivilianNotification((IFaction) this.Insulter.Clan);
    }

    public bool IsVisibleNotification
    {
      get => this._overWhat != null ? this._overWhat.IsHero : this.Insultee.CharacterObject.IsHero;
    }

    public CharacterInsultedLogEntry(
      Hero insultee,
      Hero insulter,
      CharacterObject overWhat,
      ActionNotes note)
    {
      this.Insultee = insultee;
      this.Insulter = insulter;
      this._overWhat = overWhat;
      this._gameActionNote = note;
    }

    public override TextObject GetHistoricComment(Hero talkTroop)
    {
      MBTextManager.SetTextVariable("SIDE1TROOP", this.Insultee.Name, false);
      MBTextManager.SetTextVariable("SIDE2TROOP", this.Insulter.Name, false);
      if (talkTroop == this.Insultee)
        return GameTexts.FindText("str_description_insultcharacter_I_insulted_y");
      if (talkTroop == this.Insulter)
        return GameTexts.FindText("str_description_insultcharacter_x_insulted_me");
      if (talkTroop == null)
        return GameTexts.FindText("str_description_insultcharacter_x_insulted_y");
      MBTextManager.SetTextVariable("SIDE1TROOP", ConversationHelper.HeroRefersToHero(talkTroop, this.Insultee, true), false);
      MBTextManager.SetTextVariable("SIDE2TROOP", ConversationHelper.HeroRefersToHero(talkTroop, this.Insulter, false), false);
      if (this._gameActionNote != ActionNotes.CourtshipQuarrel)
        return GameTexts.FindText("str_description_insultcharacter_x_insulted_y");
      Hero heroObject = this._overWhat.HeroObject;
      MBTextManager.SetTextVariable("SUBJECT", ConversationHelper.HeroRefersToHero(talkTroop, heroObject, false), false);
      return GameTexts.FindText("str_description_insultcharacter_x_insulted_y_courtship");
    }

    public override int AsReasonForEnmity(Hero referenceHero1, Hero referenceHero2)
    {
      return referenceHero1 == this.Insultee && referenceHero2 == this.Insulter || referenceHero2 == this.Insultee && referenceHero1 == this.Insulter ? 5 : 0;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();

    public TextObject GetNotificationText()
    {
      TextObject text = GameTexts.FindText("str_notification_quarrel");
      StringHelpers.SetCharacterProperties("LORD", this.Insultee.CharacterObject, text);
      StringHelpers.SetCharacterProperties("OTHER_LORD", this.Insulter.CharacterObject, text);
      return text;
    }

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return (object) obj == this.Insultee || (object) obj == this.Insulter;
    }

    public TextObject GetEncyclopediaText()
    {
      TextObject parent = TextObject.Empty;
      if (this._gameActionNote == ActionNotes.CourtshipQuarrel)
        parent = GameTexts.FindText("str_insult_news_courtship");
      if (this._gameActionNote == ActionNotes.ValorStrategyQuarrel)
        parent = GameTexts.FindText("str_insult_news_setback_valor");
      if (this._gameActionNote == ActionNotes.CalculatingStrategyQuarrel)
        parent = GameTexts.FindText("str_insult_news_setback_calculating");
      if (this._gameActionNote == ActionNotes.ResponsibilityStrategyQuarrel)
        parent = GameTexts.FindText("str_insult_news_setback_responsibility");
      if (this._gameActionNote == ActionNotes.LandCheatingQuarrel)
        parent = GameTexts.FindText("str_insult_news_land");
      if (this._gameActionNote == ActionNotes.TroublemakerQuarrel)
        parent = GameTexts.FindText("str_insult_news_troublemaker");
      if (this._gameActionNote == ActionNotes.HereticQuarrel)
        parent = GameTexts.FindText("str_insult_news_heretic");
      if (this._gameActionNote == ActionNotes.RuthlessBusinessQuarrel)
        parent = GameTexts.FindText("str_insult_news_ruthless_business");
      if (this._gameActionNote == ActionNotes.DishonestBusinessQuarrel)
        parent = GameTexts.FindText("str_insult_news_dishonest_business");
      if (this._gameActionNote == ActionNotes.ExtortingQuarrel)
        parent = GameTexts.FindText("str_insult_news_extorting");
      if (this._gameActionNote == ActionNotes.VengeanceQuarrel)
        parent = GameTexts.FindText("str_insult_news_vengeance");
      if (this._gameActionNote == ActionNotes.FiefQuarrel)
        parent = GameTexts.FindText("str_insult_news_fief");
      if (parent != TextObject.Empty)
      {
        StringHelpers.SetCharacterProperties("INSULTER", this.Insultee.CharacterObject, parent);
        StringHelpers.SetCharacterProperties("INSULTEE", this.Insulter.CharacterObject, parent);
        return parent;
      }
      TextObject encyclopediaText = new TextObject("{=v7sfiv5m}{INSULT_NEWS} {GAME_ACTION_NOTES}");
      encyclopediaText.SetTextVariable("INSULT_NEWS", GameTexts.FindText("str_insult_news"));
      encyclopediaText.SetTextVariable("GAME_ACTION_NOTES", GameTexts.FindText("str_game_action_note", this._gameActionNote.ToString()));
      return encyclopediaText;
    }
  }
}
